var app = getApp(), api = getApp().api;
var e = function (a) {
  if (a && a.__esModule) return a;
  var t = {};
  if (null != a) for (var e in a) Object.prototype.hasOwnProperty.call(a, e) && (t[e] = a[e]);
  return t.default = a, t;
}(require("../ec-canvas/echarts"));
function a(a, t, e) {
  return t in a ? Object.defineProperty(a, t, {
    value: e,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : a[t] = e, a;
}

function t(t, e, n, i, s, d) {
  var o, r = {
    grid: {
      left: "3%",
      right: "4%",
      bottom: "3%",
      top: "60rpx",
      containLabel: !0
    },
    tooltip: {
      trigger: "axis",
      backgroundColor: "#7f7f7f",
      textStyle: {
        color: "#fff"
      },
      position: function (a, t, e, n, i) {
        return [a[0] / 2, 0];
      },
      formatter: function (a) {
        return i < 2 ? s + " " + a[0].dataIndex + "时\n" + d + a[0].data : s[a[0].dataIndex] + "\n" + d + a[0].data;
      },
      padding: [10, 24]
    },
    xAxis: {
      type: "category",
      axisLabel: {
        show: !0,
        textStyle: {
          fontSize: 10,
          color: "#999999"
        }
      },
      data: e
    },
    yAxis: (o = {
      splitLine: {
        show: !0,
        lineStyle: {
          type: "dashed"
        }
      },
      axisLine: {
        show: !1
      },
      axisLabel: {
        show: !1
      }
    }, a(o, "axisLabel", {
      show: !1
    }), a(o, "type", "value"), o),
    series: [{
      data: n,
      type: "line",
      sampling: "average",
      symbol: "none",
      itemStyle: {
        color: "#446DFD"
      },
      areaStyle: {
        color: "rgba(68,109,253,0.3)"
      },
      smooth: !0
    }]
  };
  t.setOption(r);
}
Page({
  data: {
    api_host: '',
    info: {
      comment: 0,
      mch: 0,
      share: 0
    },
    page_loading: !0,
    plugins_list: [{
      name: "全部",
      sign: ""
    }],
    status: [{
      name: "支付金额",
      sign: "total_pay_price"
    }, {
      name: "支付订单数",
      sign: "order_num"
    }, {
      name: "支付人数",
      sign: "user_num"
    }, {
      name: "支付件数",
      sign: "goods_num"
    }],
    plugins_active: {
      name: "全部",
      sign: ""
    },
    canvas_plugins: {
      name: "全部",
      sign: ""
    },
    pay_active: {
      name: "支付金额",
      sign: "total_pay_price"
    },
    _num: "0",
    _date: "0",
    choose_list: [],
    new_msg_num: null,
    all_data: [],
    index: [0],
    newIndex: null,
    ec: {
      lazyLoad: !0
    },
    dialog: !1,
    today: "",
    yesterday: "",
    weekday: "",
    monthday: "",
    area: null,
    id: null,
    iphone_x: !1
  },
  onLoad: function (t) {
    getApp().page.onLoad(this, t);
    this.setData({
      api_host: getApp().globalData.api_host
    })
    this.getDate();
    var e = this;
    this.component = this.selectComponent("#mychart")
    this.getList()
    getApp().core.showLoading({
      title: "加载中"
    }), getApp().request({
      url: getApp().api.admin.index.user_info,
      success: function (t) {
        getApp().core.hideLoading(), 0 == t.code && (0 === t.data.user_info.is_admin && getApp().core.showModal({
          title: "提示",
          content: "\您不是后台管理员",
          showCancel: !1,
          success: function (t) {
            t.confirm && getApp().core.navigateBack();
          }
        }), e.setData(t.data), e.setData({
          is_show: !0
        }));
      }
    });
  },
  onReady: function () {
    getApp().page.onReady(this);
  },
  onShow: function () {
    getApp().page.onShow(this);
  },
  onHide: function () {
    getApp().page.onHide(this);
  },
  onUnload: function () {
    getApp().page.onUnload(this);
  },
  navigatorSubmit: function (t) {
    getApp().request({
      url: getApp().api.user.save_form_id + "&form_id=" + t.detail.formId
    }), getApp().core.navigateTo({
      url: t.detail.value.url
    });
  },
  getChart: function (a, n) {
    var i = this;
    getApp().core.showLoading({
      title: "加载中"
    })
    var s = this.data.today;
    a == this.data.yesterday && (s = this.data.yesterday);
    getApp().request({
      url: getApp().api.admin.index.table,
      data: {
        date_start: a,
        date_end: s,
        sign: i.data.pay_active ? i.data.pay_active.sign : ''
      },
      method: "post",
      success: function (a) {
        if (0 == a.code) {
          var n = a.data.list, s = [], d = [];
          "total_pay_price" == i.data.pay_active.sign ? n.forEach(function (a, t) {
            s.push(n[t].total_pay_price), d.push(n[t].created_at);
          }) : "order_num" == i.data.pay_active.sign ? n.forEach(function (a, t) {
            s.push(n[t].order_num), d.push(n[t].created_at);
          }) : "goods_num" == i.data.pay_active.sign ? n.forEach(function (a, t) {
            s.push(n[t].goods_num), d.push(n[t].created_at);
          }) : "user_num" == i.data.pay_active.sign && n.forEach(function (a, t) {
            s.push(n[t].user_num), d.push(n[t].created_at);
          });
          var o = void 0;
          switch (i.data._date) {
            case "0":
              o = i.data.today, s.forEach(function (a, t) {
                d[t] = t % 4 == 0 ? d[t] : "";
              }), d.push("24");
              break;
            case "1":
              o = i.data.yesterday, s.forEach(function (a, t) {
                t % 4 != 0 && (d[t] = "");
              }), d.push("24");
              break;

            case "2":
              o = [], s.forEach(function (a, t) {
                o.push(d[t]), d[t] = d[t].substring(5);
              });
              break;

            case "3":
              o = [], s.forEach(function (a, t) {
                o.push(d[t]), d[t] = d[t].substring(5), t % 4 != 0 && (d[t] = "");
              });
          }
          var r = i.data.pay_active.name;

          "支付金额" == i.data.pay_active.name ? r += " ￥" : r += " ", setTimeout(function () {
            getApp().core.hideLoading()
          }, 1e3); i.component.init(function (a, n, p) {
            console.log(a), console.log(n), console.log(p);
            var g = e.init(a, null, {
              width: n,
              height: p
            });
            return t(g, d, s, i.data._date, o, r), i.chart = g, g;
          });
        } else getApp().iView.$Toast({
          content: a.data.msg,
          duration: 2,
          type: "warning"
        }), getApp().iView.$Toast.hide();
      }
    })
  },
  getDate: function () {
    var a = new Date(), t = a.getFullYear(), e = a.getMonth() + 1;
    e >= 1 && e <= 9 && (e = "0" + e);
    var n = t + "-" + e + "-" + a.getDate(), i = Date.parse(new Date()), s = 1e3 * (i / 1e3 - 86400), d = new Date(s), o = d.getFullYear(), r = d.getMonth() + 1;
    r >= 1 && r <= 9 && (r = "0" + r);
    var p = o + "-" + r + "-" + d.getDate(), g = 1e3 * (i / 1e3 - 604800), u = new Date(g), c = u.getFullYear(), l = u.getMonth() + 1;
    l >= 1 && l <= 9 && (l = "0" + l);
    var h = c + "-" + l + "-" + u.getDate(), _ = 1e3 * (i / 1e3 - 2592e3), y = new Date(_), m = y.getFullYear(), f = y.getMonth() + 1;
    f >= 1 && f <= 9 && (f = "0" + f);
    var v = m + "-" + f + "-" + y.getDate();
    this.setData({
      today: n,
      yesterday: p,
      weekday: h,
      monthday: v
    });
  },
  tablist: function (a) {
    var t = a.currentTarget.dataset.date;
    this.setData({
      _date: t
    });
    var e = void 0;
    switch (t) {
      case "0":
        e = this.data.today;
        break;

      case "1":
        e = this.data.yesterday;
        break;

      case "2":
        e = this.data.weekday;
        break;

      case "3":
        e = this.data.monthday;
    }
    this.getChart(e);
  },
  toggle: function (a) {
    var t = this, e = a.currentTarget.dataset.status, n = a.currentTarget.dataset.area;
    a.currentTarget.dataset.area > 0 && t.setData({
      area: a.currentTarget.dataset.area
    });
    var i = void 0, s = void 0;
    switch (t.data._num) {
      case "0":
        i = "";
        break;

      case "1":
        i = t.data.today;
        break;

      case "2":
        i = t.data.yesterday;
        break;

      case "3":
        i = t.data.weekday;
        break;

      case "4":
        i = t.data.monthday;
    }
    switch (t.data._date) {
      case "0":
        s = t.data.today;
        break;

      case "1":
        s = t.data.yesterday;
        break;

      case "2":
        s = t.data.weekday;
        break;

      case "3":
        s = t.data.monthday;
    }
    var d = void 0;
    3 == n ? (d = t.data.status.indexOf(t.data.pay_active), t.setData({
      choose_list: t.data.status,
      index: d,
      dialog: !t.data.dialog
    })) : n < 3 && (1 == n ? d = t.data.plugins_list.indexOf(t.data.plugins_active) : 2 == n && (d = t.data.plugins_list.indexOf(t.data.canvas_plugins)),
      t.setData({
        choose_list: t.data.plugins_list,
        index: d,
        dialog: !t.data.dialog
        })), setTimeout(function () {
        e > 0 && (1 == e ? 3 == t.data.area ? (t.setData({
          pay_active: t.data.status[t.data.newIndex],
          dialog: !t.data.dialog
        }), t.getChart(s)) : 1 == t.data.area ? (t.setData({
          plugins_active: t.data.plugins_list[t.data.newIndex]
        }), t.getList(i)) : 2 == t.data.area ? (t.setData({
          canvas_plugins: t.data.plugins_list[t.data.newIndex],
          dialog: !t.data.dialog
        }), t.getChart(s)) : t.setData({
          dialog: !t.data.dialog
        }) : t.setData({
          newIndex: null,
          dialog: !t.data.dialog
        }));
      }, 500);
  },
  bindChange: function (a) {
    var t = a.detail.value[0];
    this.setData({
      newIndex: t
    });
  },
  onReady: function () {
    var a = this;
    a.getChart(a.data.today);
  },
  tab: function (a) {
    var t = a.currentTarget.dataset.num;
    this.setData({
      _num: t,
      list: []
    });
    var e = void 0;
    switch (t) {
      case "0":
        e = "";
        break;

      case "1":
        e = this.data.today;
        break;

      case "2":
        e = this.data.yesterday;
        break;

      case "3":
        e = this.data.weekday;
        break;

      case "4":
        e = this.data.monthday;
    }
    this.getList(e);
  },
  getList: function (a) {
    var t = this.data.today;
    a == this.data.yesterday && (t = this.data.yesterday);
    var e = this;
    getApp().core.showLoading({
      title: "加载中"
    }), getApp().request({
      url: getApp().api.admin.index.index,
      data: {
        date_start: a,
        date_end: t,
        sign: this.data.plugins_active.sign
      },
      method: "post",
      success: function (a) {console.log(a);
        getApp().core.hideLoading()
        if ( 0 == a.code) {
          var t = a.data.new_msg_num, n = a.data.all_data, i = a.data.admin_info;
          e.setData({
            new_msg_num: t,
            all_data: n,
            dialog: !1,
            info: i
          });
        } else getApp().core.showModal({
          content: '出错',
          duration: 2,
          type: "warning"
        });
      }
    });
  },
  goToIncomeCode: function () {
    getApp().core.navigateTo({
      url: "/pages/income-code/income-code"
    });
  },
  goToKefu: function () {
    wx.navigateTo({
      url: '/kefu/kefu?mch_id=0'
    })
  }
});